package com.lc.sell.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lc.sell.entity.Review;
import com.lc.sell.mapper.ReviewMapper;
import com.lc.sell.service.ReviewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.sell.util.TimeUtils;
import com.lc.sell.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 龙晨
 * @since 2022-04-06 09:27:10
 */
@Service
public class ReviewServiceImpl extends ServiceImpl<ReviewMapper, Review> implements ReviewService {

    @Autowired
    private ReviewMapper reviewMapper;

    @Override
    public ResultVo insetReview(Review review) {
        review.setCreateTime(TimeUtils.getNowDate());
        reviewMapper.insert(review);
        return ResultVo.ok("添加成功");
    }

    @Override
    public ResultVo selReviewStatus(String userId, String orderId) {
        Review review = reviewMapper.selectOne(new QueryWrapper<Review>().eq("userid", userId).eq("orderId", orderId));
        if (review != null){
            return ResultVo.ok("用户已对订单进行评论",review);
        }
        return ResultVo.fail("用户未对订单进行评论");
    }

    @Override
    public ResultVo selReviewList(String  mid) {
        List<Review> reviews = reviewMapper.selReviewList(mid);
        return ResultVo.ok("查询成功",reviews);
    }

    @Override
    public ResultVo selReviewByOrderId(String orderId) {
        Review review = reviewMapper.selectOne(new QueryWrapper<Review>().eq("orderId",orderId));
        return ResultVo.ok("查询成功!",review);
    }
}
